package com.yiwu.common.domain.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.*;

/**
 * @TableName Chat_session_user
 */
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
@TableName(value = "Chat_session_user")
@Data
public class ChatSessionUser extends Model<ChatSessionUser> {
    /**
     * 用户ID
     */
    @TableId
    private Long userId;

    /**
     * 联系人ID
     */
    private Long contactId;

    /**
     * 会话ID
     */
    private String sessionId;

    /**
     * 头像连接
     */
    private String avatarUrl;

    /**
     * 联系人名称
     */
    private String contactName;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;


    public boolean existence(Long userId,Long contactId) {
        QueryWrapper<ChatSessionUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("contact_id", contactId);
        long count = super.selectCount(queryWrapper);
        return count != 0;
    }

}